package logwarp

import (
	"fmt"
	"github.com/sirupsen/logrus"
	"path"
	"runtime"
	"time"
)

func Std() *logrus.Entry {
	if logrus.GetLevel() != logrus.DebugLevel {
		return logrus.NewEntry(logrus.StandardLogger())
	}
	entry := logrus.WithField("time", time.Now().Unix())
	for i := 1; ; i++ {
		_, file, line, ok := runtime.Caller(i)
		if !ok {
			break
		}
		entry = entry.WithField(fmt.Sprintf("#%d", i-1), fmt.Sprintf("%s:%d", path.Base(file), line))
	}
	return entry
}

func Warp(logger *logrus.Logger) *logrus.Entry {
	if logrus.GetLevel() != logrus.DebugLevel {
		return logrus.NewEntry(logger)
	}
	entry := logger.WithField("time", time.Now().Unix())
	for i := 1; ; i++ {
		_, file, line, ok := runtime.Caller(i)
		if !ok {
			break
		}
		entry = entry.WithField(fmt.Sprintf("#%d", i-1), fmt.Sprintf("%s:%d", path.Base(file), line))
	}
	return entry
}
